
import 'package:cbec_app/entity/home/content/content_data.dart';

class ImageAdHotAreaModel extends ContentData {
    int? borderWidth;
    int? pageMargin;
    String? subType;
    String? cornerType;
    List<HotAreaSubEntryModel>? subEntry;

  ImageAdHotAreaModel({
      this.borderWidth,
      this.pageMargin,
      this.subType,
      this.cornerType,
      this.subEntry,
  }) {
    type = 'image_ad_hot_area'; // 设置 type 属性
  }

  // 从 JSON 创建实例
  factory ImageAdHotAreaModel.fromJson(Map<String, dynamic> json) {
    return ImageAdHotAreaModel(
      borderWidth: json['border_width'] ?? 0,
      pageMargin: json['page_margin'] ?? 0,
      subType: json['sub_type'] ?? '',
      cornerType: json['corner_type'] ?? '',
      subEntry: (json['sub_entry'] as List)
          .map((item) => HotAreaSubEntryModel().fromJson(item))
          .toList(),
    );
  }

  @override
  ContentData fromJson(Map<String, dynamic> json) {
    throw ImageAdHotAreaModel.fromJson(json);
  }

  // 转换为 JSON
  @override
  Map<String, dynamic> toJson() {
    return {
      'border_width': borderWidth,
      'page_margin': pageMargin,
      'sub_type': subType,
      'corner_type': cornerType,
      'sub_entry': subEntry?.map((item) => item.toJson()).toList(),
    };
  }
}

// HotAreaSubEntryModel 类
class HotAreaSubEntryModel {
    int? imageHeight;
    String? imageUrl;
    int? imageWidth;
    String? title;
    List<HotAreaModel>? hotAreas;

  HotAreaSubEntryModel({
      this.imageHeight,
      this.imageUrl,
      this.imageWidth,
      this.title,
      this.hotAreas,
  });

  // 从 JSON 创建实例
  HotAreaSubEntryModel fromJson(Map<String, dynamic> json) {
    return HotAreaSubEntryModel(
      imageHeight: json['image_height'] ?? 0,
      imageUrl: json['image_url'] ?? '',
      imageWidth: json['image_width'] ?? 0,
      title: json['title'] ?? '',
      hotAreas: (json['hot_areas'] as List)
          .map((item) => HotAreaModel().fromJson(item))
          .toList(),
    );
  }

  // 转换为 JSON
  Map<String, dynamic> toJson() {
    return {
      'image_height': imageHeight,
      'image_url': imageUrl,
      'image_width': imageWidth,
      'title': title,
      'hot_areas': hotAreas?.map((item) => item.toJson()).toList(),
    };
  }
}

// HotAreaModel 类
class HotAreaModel {
    int? startX;
    String? linkType;
    int? endX;
    int? startY;
    int? endY;
    String? linkUrl;
    String? linkTitle;
    int? linkId;

  HotAreaModel({
      this.startX,
      this.linkType,
      this.endX,
      this.startY,
      this.endY,
      this.linkUrl,
      this.linkTitle,
      this.linkId,
  });

  // 从 JSON 创建实例
  HotAreaModel fromJson(Map<String, dynamic> json) {
    return HotAreaModel(
      startX: json['start_x'] ?? 0,
      linkType: json['link_type'] ?? '',
      endX: json['end_x'] ?? 0,
      startY: json['start_y'] ?? 0,
      endY: json['end_y'] ?? 0,
      linkUrl: json['link_url'] ?? '',
      linkTitle: json['link_title'] ?? '',
      linkId: json['link_id'] ?? 0,
    );
  }

  // 转换为 JSON
  Map<String, dynamic> toJson() {
    return {
      'start_x': startX,
      'link_type': linkType,
      'end_x': endX,
      'start_y': startY,
      'end_y': endY,
      'link_url': linkUrl,
      'link_title': linkTitle,
      'link_id': linkId,
    };
  }
}

